package com.lwei.tallybook.client.action;

import com.lwei.tallybook.base.domain.Account;
import com.lwei.tallybook.client.controller.BaseController;
import com.lwei.tallybook.service.service.AccountService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import javax.annotation.Resource;

import java.util.List;

/**
 * home
 * @author sks.lwei
 */
@Controller
public class HomeAction extends BaseController {

    @Resource
    private AccountService accountService;

    @GetMapping("/index")
    public String home(Model model){
        Account account = currentUser();
        model.addAttribute("loginName", account.getUserName());
        return "index";
    }

    @GetMapping("/login")
    public String toLogin(Model model){
        List<Account> accounts = accountService.listAll();
        model.addAttribute("accounts", accounts);
        return "login";
    }

    @GetMapping("/changePassword")
    public String changePassword(Model model){
        model.addAttribute("account", currentUser());
        return "/setting/chpwd";
    }

    @GetMapping("/*")
    public void toHtml(){}
}
